home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wsc4d21.zip / DISPLAY.PAS next >
Pascal/Delphi Source File  |  1997-06-09  |  3KB  |  114 lines

  1. unit DisplayUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   wsc,
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, Menus,
  9.   ExtCtrls, StdCtrls;
  10.  
  11. procedure DisplayChar(Memo: TMemo; TheChar : Char);
  12. procedure DisplayString(Memo: TMemo; Text : String);
  13. procedure DisplayLine(Memo: TMemo; Text : String);
  14. procedure DisplayError(Memo: TMemo; Code : Integer);
  15.  
  16. var
  17.   LineCount : Integer;
  18.  
  19. implementation
  20.  
  21. {Display character}
  22.  
  23. procedure DisplayChar(Memo: TMemo; TheChar : Char);
  24. var
  25.    TheString : String;
  26.    Ch : Char;
  27. begin
  28.    if TheChar <> Chr(13) then
  29.      {ignore CR}
  30.      begin
  31.        if TheChar = Chr(10) then
  32.          begin
  33.            {create new line}
  34.            Memo.Lines.Add('');
  35.            Inc(LineCount);
  36.          end
  37.        else
  38.          begin
  39.            {printable chars only}
  40.            if (TheChar<' ') or (TheChar>'~') then TheChar := ' ';
  41.            {append char}
  42.            TheString := Memo.Lines.Strings[LineCount] + TheChar;
  43.            Memo.Lines.Strings[LineCount] := TheString;
  44.          end
  45.    end
  46. end;
  47.  
  48. {Display string}
  49.  
  50. procedure DisplayString(Memo: TMemo; Text : String);
  51. var
  52.   S : String;
  53.   I   : Integer;
  54.   Len : Integer;
  55. begin
  56.   Len := Length(Text);
  57.   for I := 1 to Len do
  58.     if (Text[I]<' ') or (Text[I]>'~') then Text[I] := ' ';
  59.   S := Memo.Lines.Strings[LineCount];
  60.   Memo.Lines.Strings[LineCount] := S + Text;
  61. end;
  62.  
  63. {Display String & CRLF}
  64.  
  65. procedure DisplayLine(Memo: TMemo; Text : String);
  66. begin
  67.   DisplayString(Memo,Text);
  68.   DisplayChar(Memo,Chr(10))
  69. end;
  70.  
  71. (* Display error text *)
  72.  
  73. procedure DisplayError(Memo: TMemo; Code : Integer);
  74. var
  75.    Text : String;
  76. {$IFDEF WIN32}
  77.    Ptr  : PChar;
  78. {$ENDIF}
  79. begin
  80.   if Code <0 then
  81.     begin
  82.       case Code of
  83.         IE_BADID: Text := 'Bad port ID';
  84.         IE_OPEN:  Text := 'Cannot open port';
  85.         IE_NOPEN: Text := 'Port already open';
  86.         IE_MEMORY:   Text := 'Cannot allocate memory';
  87.         IE_DEFAULT:  Text := 'Error in default parameters';
  88.         IE_HARDWARE: Text := 'Hardware error';
  89.         IE_BYTESIZE: Text := 'Unsupported byte size';
  90.         IE_BAUDRATE: Text := 'Unsupported baud rate';
  91.         WSC_RANGE:   Text := 'Parameter out of range';
  92.         WSC_ABORTED: Text := 'Shareware version corrupted';
  93. {$IFDEF WIN32}
  94.         WSC_WIN32ERR:
  95.           begin
  96.             GetMem(Ptr, 120);
  97.             Code := SioWinError(Ptr, 120);
  98.             DisplayLine(Memo,StrPas(Ptr));
  99.             Text := Format(' Win32 error %d.',[Code]);
  100.             FreeMem(Ptr,120);
  101.           end;
  102. {$ENDIF}
  103.         WSC_EXPIRED: Text := 'Shareware version expired';
  104.         else Text := 'Unknown error';
  105.       end;
  106.       DisplayLine(Memo,Text);
  107.     end
  108. end;
  109.  
  110. (* initialization *)
  111. begin
  112.   LineCount := 0;
  113. end.
  114.